package com.zenithmind.common.result;

import lombok.Getter;

@Getter
public enum ResultCode {
    SUCCESS(200, "成功"),
    FAIL(400, "失败"),
    UNAUTHORIZED(401, "未认证"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "资源不存在"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    BAD_REQUEST(400, "请求错误"),
    METHOD_NOT_ALLOWED(405, "方法不被允许"),
    NOT_ACCEPTABLE(406, "不可接受"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFLICT(409, "冲突"),
    GONE(410, "已移除"),
    UNSUPPORTED_MEDIA_TYPE(415, "不支持的媒体类型"),
    NOT_IMPLEMENTED(501, "未实现"),
    BAD_GATEWAY(502, "错误的网关"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),
    PRECONDITION_FAILED(412, "先决条件失败"),
    PAYLOAD_TOO_LARGE(413, "请求实体过大"),
    URI_TOO_LONG(414, "请求的URI过长"),
    RANGE_NOT_SATISFIABLE(416, "范围不可满足"),
    EXPECTATION_FAILED(417, "预期失败"),
    TOO_MANY_REQUESTS(429, "请求过多"),
    LOCKED(423, "锁定"),
    FAILED_DEPENDENCY(424, "依赖失败"),
    UPGRADE_REQUIRED(426, "需要升级"),
    PRECONDITION_REQUIRED(428, "需要先决条件"),
    TOO_EARLY(425, "太早"),
    UNAVAILABLE_FOR_LEGAL_REASONS(451, "因法律原因不可用"),
    VARIANT_ALSO_NEGOTIATES(506, "变体协商也协商"),
    INSUFFICIENT_STORAGE(507, "存储空间不足"),
    LOOP_DETECTED(508, "检测到循环"),
    NOT_EXTENDED(510, "未扩展"),
    NETWORK_AUTHENTICATION_REQUIRED(511, "需要网络认证"),
    LOGIN_REQUIRED(401, "登录所需"), // 未认证
    INVALID_CREDENTIALS(401, "用户或密码错误"), // 无效的用户名或密码
    ACCOUNT_LOCKED(403, "账户被锁定"), // 账户被锁定
    PASSWORD_EXPIRED(403, "密码已过期"), // 密码已过期
    ACCOUNT_DISABLED(403, "账户已禁用"), // 账户已禁用
    SESSION_EXPIRED(401, "会话已过期"), // 会话已过期
    USER_NOT_EXIST (404, "用户不存在"),
    //用户修改失败
    USER_UPDATE_FAILED(500, "用户修改失败"),
    
    // 业务错误
    BUSINESS_ERROR(10000, "业务错误"),
    // 参数错误
    PARAM_ERROR(10001, "参数错误"),
    // 用户名已存在
    USERNAME_EXIST(10002, "用户名已存在"),
    // 邮箱已存在
    EMAIL_EXIST(10003, "邮箱已存在"),
    // 手机号已存在
    MOBILE_EXIST(10004, "手机号已存在"),
    // 角色不存在
    ROLE_NOT_EXIST(10005, "角色不存在"),
    // 权限不存在
    PERMISSION_NOT_EXIST(10006, "权限不存在"),
    // 验证码错误
    INVALID_CODE(10007, "验证码错误或已过期"),
    // 邮箱必须设置
    EMAIL_REQUIRED(10008, "用户邮箱未设置"),
    // 系统错误
    SYSTEM_ERROR(20000, "系统错误"),
    INVALID_PARAM(400, "无效的参数"),
    // 验证码相关
    VERIFICATION_CODE_ERROR(400, "验证码错误或已过期");

    private final Integer code;
    private final String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static ResultCode getByCode(Integer code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return FAIL; // 默认返回失败
    }
}
